<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      xmlns:th="http://www.thymeleaf.org"
      layout:decorator="layout">
<head>
    <title th:inline="text">Edit &middot; [[${project.id}]]</title>
</head>
<body>
<div layout:fragment="header-container"></div>
<div layout:fragment="content" class="container">
    <div class="main-body--wrapper">
        <div class="admin-index--title">
            <div class="content--title search-title" th:inline="text">
                <a th:href="@{/admin}">Admin</a> : <a th:href="@{/admin/projects}">Projects</a> : Edit [[${project.id}]]
            </div>
        </div>
        <form th:action="@{'/admin/projects/' + ${project.id}}" method="post" th:object="${project}">
            <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
            <label for="groupId">Group ID</label>
            <input type="text" name="groupId" id="groupId" th:value="${groupId}" value="org.springframework"/>
            <label for="id">ID</label>
            <input type="text" th:field="*{id}"/>

            <label for="parentId">Parent Project Id (e.g.: 'spring-data')</label>
            <input type="text" name="parentId" id="parentId" th:value="${project.getParentId()}"/>

            <label for="groupId">Category</label>
            <select th:field="*{category}">
                <option th:each="c : ${categories}"
                        th:value="${c}"
                        th:text="${c}">incubator
                </option>
            </select>
            <label for="name">Name</label>
            <input type="text" th:field="*{name}"/>
            <label for="repoUrl">Repository URL</label>
            <input type="text" th:field="*{repoUrl}"/>
            <label for="siteUrl">Site URL</label>
            <input type="text" th:field="*{siteUrl}"/>
            <label for="stackOverflowTags">StackOverflow Tags (comma-separated list)</label>
            <input type="text" th:field="*{stackOverflowTags}"/>
            <label for="displayOrder">Display order</label>
            <input type="text" th:field="*{displayOrder}"/>
            <label for="rawBootConfig">Boot configuration content (Asciidoctor format)</label>
            <textarea id="rawBootConfig" th:field="*{rawBootConfig}" name="rawBootConfig" class="span12" rows="5"></textarea>
            <label for="rawOverview">Overview content (Asciidoctor format)</label>
            <textarea id="rawOverview" th:field="*{rawOverview}" name="rawOverview" class="span12" rows="5"></textarea>
            <fieldset>
                <legend>Releases</legend>
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <td>Delete?</td>
                        <td>Artifact ID</td>
                        <td>Version</td>
                        <td>Current</td>
                        <td>Reference URL</td>
                        <td>API URL</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="release,releaseStat : ${project.projectReleases}">
                        <td><input type="checkbox" name="releasesToDelete"
                                   th:value="*{projectReleases[__${releaseStat.index}__].version}"></td>
                        <td><input type="text" th:field="*{projectReleases[__${releaseStat.index}__].artifactId}"/></td>
                        <td><input type="text" th:field="*{projectReleases[__${releaseStat.index}__].version}"/></td>
                        <td><input type="checkbox" th:field="*{projectReleases[__${releaseStat.index}__].current}"
                                   value="true"/></td>
                        <td><input type="text" th:field="*{projectReleases[__${releaseStat.index}__].refDocUrl}"/></td>
                        <td><input type="text" th:field="*{projectReleases[__${releaseStat.index}__].apiDocUrl}"/></td>
                    </tr>
                    <tr th:with="size=${project.projectReleases.size()}">
                        <td></td>
                        <td><input type="text" th:field="*{projectReleases[__${size}__].artifactId}"/></td>
                        <td><input type="text" th:field="*{projectReleases[__${size}__].version}"/></td>
                        <td><input type="checkbox" th:field="*{projectReleases[__${size}__].current}" value="true"/>
                        </td>
                        <td><input type="text" th:field="*{projectReleases[__${size}__].refDocUrl}"/></td>
                        <td><input type="text" th:field="*{projectReleases[__${size}__].apiDocUrl}"/></td>
                    </tr>
                    </tbody>
                </table>
            </fieldset>
            <fieldset>
                <legend>Samples</legend>
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <td>Delete?</td>
                        <td>Display order</td>
                        <td>Title</td>
                        <td>Description</td>
                        <td>URL</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="sample,sampleStat : ${project.projectSamples}">
                        <td><input type="checkbox" name="samplesToDelete"
                                   th:value="*{projectSamples[__${sampleStat.index}__].displayOrder}"></td>
                        <td><input type="text" th:field="*{projectSamples[__${sampleStat.index}__].displayOrder}"/></td>
                        <td><input type="text" th:field="*{projectSamples[__${sampleStat.index}__].title}"/></td>
                        <td><textarea th:field="*{projectSamples[__${sampleStat.index}__].description}"></textarea></td>
                        <td><input type="text" th:field="*{projectSamples[__${sampleStat.index}__].url}"/></td>
                    </tr>
                    <tr th:with="size=${project.projectSamples.size()}">
                        <td></td>
                        <!--/* Changing display order default value to something else than maxint will break everything. */-->
                        <td><input type="text" th:name="'projectSamples[' + ${size} + '].displayOrder'"
                                   th:value="${projectSampleDisplayOrder}"/></td>
                        <td><input type="text" th:field="*{projectSamples[__${size}__].title}"/></td>
                        <td><textarea th:field="*{projectSamples[__${size}__].description}"></textarea></td>
                        <td><input type="text" th:field="*{projectSamples[__${size}__].url}"/></td>
                    </tr>
                    </tbody>
                </table>
            </fieldset>
            <input type="submit" value="Save"/>
        </form>
    </div>
</div>
</body>
</html>
